<?php
   require("conf.php");
  $yhendus=new mysqli($host, $user, $pw, $db);
  session_start();
  if(isSet($_REQUEST["kasutajanimi"])){
     $kask=$yhendus->prepare(
      "SELECT roll FROM user WHERE tnimi=? AND paroolir2si=PASSWORD(?)");
     $knimiparool=$_REQUEST["kasutajanimi"]."_".$_REQUEST["parool"];
     $kask->bind_param("ss", $_REQUEST["kasutajanimi"], $knimiparool);
     $kask->bind_result($roll);
     $kask->execute();
     if($kask->fetch()){
         $_SESSION["kasutajanimi"]=$_REQUEST["kasutajanimi"];
         $_SESSION["roll"]=$roll;
         $kask->close();
     }
  }
  if(isSet($_REQUEST["lahku"])){
     unset($_SESSION["kasutajanimi"]);
     unset($_SESSION["roll"]);
  }
  
?>
<!DOCTYPE HTML>
<!--
	Minimaxing 3.0 by HTML5 UP
	html5up.net | @n33co
	Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
	<head>
		<title>Avaleht</title>
		
    
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<meta name="description" content="" />
		<meta name="keywords" content="" />
		<script src="js/jquery.min.js"></script>
		<script src="js/config.js"></script>
		<script src="js/skel.min.js"></script>
		<script src="js/skel-panels.min.js"></script>
		<noscript>
			<link rel="stylesheet" href="css/skel-noscript.css" />
			<link rel="stylesheet" href="css/style.css" />
			<link rel="stylesheet" href="css/style-desktop.css" />
		</noscript>
		<!--[if lte IE 9]><link rel="stylesheet" href="css/ie9.css" /><![endif]-->
		<!--[if lte IE 8]><script src="js/html5shiv.js"></script><![endif]-->
	
	</head>
	<body>
	<!-- ********************************************************* -->
		<div id="header-wrapper">
			<div class="container">
				<div class="row">
					<div class="12u">
						
						<header id="header">
							<h1><a href="logimine.php" id="logo">Arvutihooldus ja parandus</a></h1>
							<nav id="nav">
								<?php if(!isset($_SESSION["kasutajanimi"])){echo"<a href='logimine.php'>Login</a>";}?>
							
							</nav>
						</header>
					
					</div>
				</div>
			</div>
		</div>
		<div id="main">
			<div class="container">
				<div class="row main-row">
					<div class="12u">
						
						<section>
							<h2>logimine</h2>
								<?php if(isSet($_SESSION["kasutajanimi"])): ?>
										Tere, <?php echo $_SESSION["roll"]." ".$_SESSION["kasutajanimi"];

										if(isset($_SESSION["kasutajanimi"]) and ($_SESSION['roll']=='haldur'))
										  {
											require("haldur.php");
										  }
										else if(isset($_SESSION["kasutajanimi"]) and ($_SESSION['roll']=='tehnik')){
											require("tehnik.php");
											}?>
															
										<br /><br /><a href="?lahku=jah">lahku</a>
										
										
										
										<?php else: ?>
										 <form action="?" method="post">
										  <dl>
											<dt>Kasutajanimi:</dt>
											<dd><input type="text" name="kasutajanimi" /></dd>
											<dt>Parool:</dt>
											<dd><input type="password" name="parool" /></dd>
											<dd><input type="submit" value="Sisesta" /></dd>
										  </dl>
										 </form>
										<?php endif ?>
						
							
						</section>
					
					</div>
				</div>
			</div>
		</div>
		<div id="footer-wrapper">
			<div class="container">
			
				<div class="row">
					<div class="12u">

						<div id="copyright">
							 Kujundus: <a href="http://html5up.net">HTML5 UP</a> | Pildid: <a href="http://fotogrph.com">fotogrph</a> | Töö autorid <a href="mailto:alisiko1@tlu.ee">-</a>
						</div>

					</div>
				</div>
			</div>
		</div>
	<!-- ********************************************************* -->
	</body>
</html>
